local view = require 'views.view'

---@class multi_child_view: view
---@field children view[]
local multi_child_view = view:new_view_type()

---@class multi_child_view.renderer: view.renderer
---@field child_renderers view.renderer[]
multi_child_view.renderer = view.renderer:new_renderer_type()

function multi_child_view:create_renderer_instance()
    local child_renderers = {}
    for i = 1, #self.children do
        child_renderers[i] = self.children[i]:create_renderer_instance()
    end

    return self:set_renderer_prototype {
        child_renderers = child_renderers
    }
end

---@param render_rect rect
---@param view multi_child_view
function multi_child_view.renderer:render(render_rect, view)
    for i = 1, #self.child_renderers do
        local r = self.child_renderers[i]
        local v = view.children[i]
        
        r:render(render_rect, v)
    end
end

function multi_child_view.renderer:destroy()
    for _, r in ipairs(self.child_renderers) do
        r:destroy()
    end
end

return multi_child_view
